<?php
//查询所有类别
$con = mysqli_connect('localhost', 'root', 'root');
if (!$con) {
    die('连接失败') . mysqli_connect_error();
}
mysqli_select_db($con, 'blog');
mysqli_set_charset($con, 'utf8');
$sql = "select * from blog_type";
$result = mysqli_query($con, $sql);
$type_list = [];
while ($row = mysqli_fetch_assoc($result)) {
    $type_list[] = $row;
}
mysqli_close($con);

//查询博客的
$con = mysqli_connect('localhost', 'root', 'root');
if (!$con) {
    die('连接失败') . mysqli_connect_error();
}
mysqli_select_db($con, 'blog');
mysqli_set_charset($con, 'utf8');
$sql = "select id,title from blog order by id desc";
$result = mysqli_query($con, $sql);
$blog_list = [];
while ($row = mysqli_fetch_assoc($result)) {
    $blog_list[] = $row;
}
mysqli_close($con);

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>博客</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .list-unstyled li{
            line-height: 30px;
        }
        .list-unstyled li a{
            font-size: 16px;
            color: #555;
        }

    </style>

</head>
<body>
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <?php
                foreach ($type_list as $key => $value) {
                    ?>
                    <li class="<?php echo $value['type_name'] == 'php' ? 'active' : '' ?>"><a
                                href="#"><?php echo $value['type_name'] ?></a></li>
                <?php }
                ?>
            </ul>
        </div>
    </div>
</nav>
<div class="container">
    <ul class="list-unstyled">
        <?php
        foreach ($blog_list as $key => $blog) {
            ?>
            <li><a href="detail.php?id=<?php echo $blog['id']?>"><?php echo $blog['title'] ?></a></li>
        <?php }
        ?>
    </ul>
</div>

</body>
</html>